<?php
/**
 * 队列，内容审核（打分）后，处理关联的wiki（wiki设计师推荐）
 */

use Biz\model\wiki\ObjRelateWiki as mObjRelateWiki;
use Biz\model\wiki\Wiki as mWiki;
use Doraemon\model\AdmUserType as mAdmUserType;
use Doraemon\model\Member as mMember;

class AfterAuditContentAction extends QueueActionPlugin
{
    public function main()
    {
        $objId = $this->getRequest()->getPost("obj_id");
        if ($objId) {
            $uid = \Doraemon\tools\IdParse::getUid($objId);
            $userInfo = \Doraemon\service\User::getBasicUserInfo($uid);
            if ($userInfo && $userInfo['type'] == mMember::AUTH_USER_DESIGNER) {//认证设计师
                $isBlack = mAdmUserType::isBlevelsByuid($uid);
                if (!$isBlack) {//非B级用户
                    $list = mObjRelateWiki::getByWhere(['obj_id' => $objId, 'uid' => $uid, 'status' => mObjRelateWiki::STATUS_NORMAL]);
                    if ($list) {
                        $wikiIds = array_column($list, 'wiki_id');
                        $wikiIds = array_unique(array_filter($wikiIds));
                        $result = mWiki::updateData(['designer_share' => 1], ['id' => $wikiIds, 'designer_share' => 0]);
                        if (!$result) {
                            \Doraemon\tools\Log::debug("更新wiki的designer_share失败", mWiki::log());
                        }
                    }
                }
            }
        }
        return $this->setSuccess();
    }
}